package banco.proadi;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import utilidades.FormatarData;

import banco.Banco;
import dominio.proadi.Proadi;
import dominio.proadi.Proadi_Mensal;
import fachada.proadi.Fachada_Proadi_Mensal;

public class Proadi_Mensal_DAO implements Fachada_Proadi_Mensal {

	/* (non-Javadoc)
	 * @see banco.proadi.Fachada_Proadi_Mensal#insertProadi_Mensal(dominio.proadi.Proadi_Mensal, dominio.proadi.Proadi)
	 */
	@SuppressWarnings("finally")
	public void insertProadi_Mensal(Proadi_Mensal pmensal, Proadi proadi) throws ClassNotFoundException, IOException {
	        
	        Connection conn = null;
	        PreparedStatement stmt = null;
	        ResultSet rs = null;
	        
	        try {
	            conn = Banco.getConexaoEXTRATOPAES();
	            stmt = conn.prepareStatement("insert into proadi_mensal values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
	            stmt.setString(1, FormatarData.formatar(pmensal.getData()));
	            stmt.setFloat(2, pmensal.getVr_icms());
	            stmt.setFloat(3, pmensal.getVr_finan_proadi());
	            stmt.setFloat(4, pmensal.getPz());
	            stmt.setFloat(5, pmensal.getPref());
	            stmt.setFloat(6, pmensal.getCpmf());
	            stmt.setFloat(7, pmensal.getIof());
	            stmt.setFloat(8, pmensal.getTotal_pagar());
	            stmt.setString(9, proadi.getFilial().trim());
	            stmt.setString(10, proadi.getCliente().getCnpj().trim());
	            stmt.setFloat(11, pmensal.getEstoque());
	            stmt.executeUpdate();
	        }
	        catch (SQLException ex) {
	            ex.printStackTrace();
	        }
	        
	        catch (Exception e) {
	        	e.printStackTrace();
	        }
	        finally {
		        Banco.closeConexao(conn, rs, stmt);
	        }
	}
	
}
